package com.estate.struts.actions;

import java.util.Date;
import java.util.List;

import com.estate.business.DocumentService;
import com.estate.business.EfileService;
import com.estate.business.LibraryService;
import com.estate.vo.Vo;
import com.estate.vo.impl.LibraryVo;

public class LibraryAction extends EstateSupport {
	
	private String method;
	private int id;
	private String libraryNum;
	private String libraryName;
	private String deptName;
	private Date buildDate;
	private LibraryService libraryService;
	private String multiType;
	private String multiDelete;
	private String delStr;
	private String deleteId;
	private String modifyId;
	private EfileService efileService;
	
	
	public String execute() throws Exception{
		
		String page="";
		if("list".equals(method)){
			List<Vo> voList=libraryService.findAllLibrary();
			this.getSession().setAttribute("libraryList", voList);
			if(this.getMultiType() != null && this.getMultiType().equals("true")){
				this.getRequest().setAttribute("multiType", new Boolean(true));
			}else{
				this.getRequest().setAttribute("multiType", new Boolean(false));
			}
			page="list";
		} else if("delete".equals(method)){
			if ("true".equals(multiDelete)) {
				System.out.println("!!!!!!!!!"+delStr);
				if (delStr != null && !"".equals(delStr) && !",".equals(delStr)) {
					String[] delArray = delStr.split(",");
					for (int i = 0; i < delArray.length; i++) {
						libraryService.deleteByPK(Integer
								.parseInt(delArray[i]));
					}
				}
			} else {
				libraryService.deleteByPK(Integer.parseInt(deleteId));
			}
			page="refresh";
		} else if("modify".equals(method)){
			Vo vo=libraryService.findByPK(Integer.parseInt(modifyId));
			this.getSession().setAttribute("modifyList", vo);
			page="modify";
		} else if("update".equals(method)){
			LibraryVo vo=(LibraryVo)libraryService.findByPK(Integer.parseInt(modifyId));
			vo.setId(Integer.parseInt(modifyId));
			vo.setLibraryName(libraryName);
			vo.setLibraryNum(libraryNum);
			vo.setDeptName(deptName);
			libraryService.update(vo);
			page="refresh";
		}
		return page;
		
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getMethod() {
		return method;
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getLibraryNum() {
		return libraryNum;
	}
	public void setLibraryNum(String libraryNum) {
		this.libraryNum = libraryNum;
	}
	public String getLibraryName() {
		return libraryName;
	}
	public void setLibraryName(String libraryName) {
		this.libraryName = libraryName;
	}
	public Date getBuildDate() {
		return buildDate;
	}
	public void setBuildDate(Date buildDate) {
		this.buildDate = buildDate;
	}

	public void setLibraryService(LibraryService libraryService) {
		this.libraryService = libraryService;
	}

	public LibraryService getLibraryService() {
		return libraryService;
	}

	public void setMultiType(String multiType) {
		this.multiType = multiType;
	}

	public String getMultiType() {
		return multiType;
	}

	public void setMultiDelete(String multiDelete) {
		this.multiDelete = multiDelete;
	}

	public String getMultiDelete() {
		return multiDelete;
	}

	public void setDelStr(String delStr) {
		this.delStr = delStr;
	}

	public String getDelStr() {
		return delStr;
	}

	public void setDeleteId(String deleteId) {
		this.deleteId = deleteId;
	}

	public String getDeleteId() {
		return deleteId;
	}

	public void setModifyId(String modifyId) {
		this.modifyId = modifyId;
	}

	public String getModifyId() {
		return modifyId;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	public String getDeptName() {
		return deptName;
	}



	public void setEfileService(EfileService efileService) {
		this.efileService = efileService;
	}

	public EfileService getEfileService() {
		return efileService;
	}

}
